// utils/week.js

// 获取今天日期 yyyy/MM/dd
export function getTodayDate() {
  const d = new Date()
  return `${d.getFullYear()}/${pad(d.getMonth() + 1)}/${pad(d.getDate())}`
}

// 统一的 pad 补零函数
function pad(n) {
  return n < 10 ? '0' + n : n
}

// 获取当前是第几周（基于 storage 中的 semesterStartDate）
export function getWeekNumber(date = new Date()) {
  const semesterStartStr = uni.getStorageSync('semesterStartDate') || '2025-02-19'
  const semesterStart = new Date(semesterStartStr)

  const diffTime = date.getTime() - semesterStart.getTime()
  const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
  const week = Math.floor(diffDays / 7) + 1
  return week < 1 ? 1 : week
}

// 获取 “第几周 周几” 信息
export function getWeekInfo(dateStr) {
  const d = new Date(dateStr)
  const weekdayMap = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
  const weekday = weekdayMap[d.getDay()]
  const weekNumber = getWeekNumber(d)
  return `第${weekNumber}周 ${weekday}`
}